package com.woniuxy.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.*;
import com.woniuxy.service.StaffevaService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Staffeva)表控制层
 *
 * @author makejava
 * @since 2021-05-15 14:52:40
 */
@RestController
@RequestMapping("staffeva")
public class StaffevaController {
    /**
     * 服务对象
     */
    @Resource
    private StaffevaService staffevaService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Staffeva selectOne(Integer id) {
        return this.staffevaService.queryById(id);
    }

    /**
     * 查询所有数据
     *
     * @param
     * @return 单条数据
     */
    @GetMapping("selectAll")
    public PageInfo<Staffeva> selectAll(int startpage, int pagesize){
        PageHelper.startPage(startpage,pagesize);
        Page<Staffeva> page = (Page<Staffeva>) this.staffevaService.queryAll();
        PageInfo<Staffeva> pageInfo = new PageInfo<>(page);
        return pageInfo;
    }

    /**
     * 模糊查询数据
     *
     * @param
     * @return 单条数据
     */
    @PostMapping("search")
    public PageInfo<Staffeva> search(@RequestBody StaffevaDto StaffevaDto){
        PageHelper.startPage(StaffevaDto.getPage(),StaffevaDto.getLimit());
        Page<Staffeva> page =(Page<Staffeva>) this.staffevaService.search(StaffevaDto.getStaffeva());
        PageInfo<Staffeva>pageInfo = new PageInfo<>(page);
        return pageInfo;
    }

    /**
     * 添加一条数据
     *
     * @param staffeva
     * @return 单条数据
     */
    @PostMapping("insertOne")
    public Staffeva InsertOne(Staffeva staffeva) {
        return this.staffevaService.insert(staffeva);
    }


    /**
     * 添加一条数据
     *
     * @param staffeva
     * @return 单条数据
     */
    @PostMapping("updateOne")
    public Staffeva UpdateOne(Staffeva staffeva) {
        return this.staffevaService.update(staffeva);
    }

    /**
     * 删除一条数据
     *
     * @param staffevaId
     * @return 单条数据
     */
    @PostMapping("deleteOne/{staffevaId}")
    public boolean DelectOne(@PathVariable("staffevaId") Integer staffevaId) {
        return this.staffevaService.deleteById(staffevaId);
    }

   /**
    * 技师的评价细节
    * "servicetotal"://服务订单总数
    * "appraisetotal"://综合好评
    * staffevaslist:
    * "staffevalist"
    * */
   @PostMapping("selectstaff")
   @ApiOperation("技师的评价细节")
   public ResponseEntity<Staffevatotal> selectstaff(@RequestBody StaffevaDto staffevaDto){
       System.out.println("技师评价细节"+staffevaDto.toString());
       Integer staffevaStaff = Integer.valueOf(staffevaDto.getStaffeva().getStaffevaStaff());
       Staffevatotal staffevatotal = this.staffevaService.selectstaff(staffevaStaff, staffevaDto.getPage(), staffevaDto.getLimit());
       if (staffevatotal != null){
           return new ResponseEntity(1,"技师评价细节查询成功",staffevatotal);
       }
       return new ResponseEntity(0,"技师的评价细节查询失败");
   }



}
